package com.sgd.cli.example;

import picocli.CommandLine;
import picocli.CommandLine.Option;

import java.util.concurrent.Callable;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 *
 * @author su.gd
 * @date 2023-11-21
 */
public class Login implements Callable<Integer> {

    @Option(names = {"-u","--user"},description = "User name")
    String user;

    /**
     * interactive 参数设置为true,表示该选项支持交互式输入
     * arity = "0..1"，这样指令中就可以直接指定值了，一旦指定值，就不会有交互式输入了
     */
    @Option(names = {"-p", "--password"}, arity = "0..1", description = "Password", interactive = true)
    String password;

    @Option(names = {"-cp", "--checkPassword"}, arity = "0..1", description = "checkPassword", interactive = true)
    String checkPassword;

    /**
     * 写具体的业务逻辑
     * @return
     * @throws Exception
     */
    @Override
    public Integer call() throws Exception {
        System.out.println("password: " + password);
        System.out.println("checkPassword: " + checkPassword);
        return 0;
    }

    public static void main(String[] args) {
        // 用户必须在命令中指定需要交互式输入的选项
        new CommandLine(new Login()).execute("-u", "user123", "-p", "123", "-cp");
    }
}
